package com.gotye.hockeygame.objects;

import android.opengl.GLES20;

import com.gotye.hockeygame.data.VertexArray;
import com.gotye.hockeygame.objects.ObjectBuilder.GeneratedData;
import com.gotye.hockeygame.objects.ObjectBuilder.DrawCommand;
import com.gotye.hockeygame.programs.TextureShaderProgram;
import com.gotye.hockeygame.util.Geometry.Point;
import com.gotye.hockeygame.util.Geometry.Cylinder;

import java.util.List;


/**
 * Created by Michael.Ma on 2016/3/3.
 */
public class Puck {
    private static final int POSITION_COMPONENT_COUNT = 3;

    public final float radius, height;

    private final VertexArray vertexArray;
    private final List<DrawCommand> drawList;

    public Puck(float radius, float height, int numPointsAroundPuck) {
        GeneratedData generatedData = ObjectBuilder.createPuck(new Cylinder(
                new Point(0f, 0f, 0f), radius, height), numPointsAroundPuck);
        this.radius = radius;
        this.height = height;

        vertexArray = new VertexArray(generatedData.vertexData);
        drawList = generatedData.drawList;
    }

    public void bindData(TextureShaderProgram textureShaderProgram) {
        vertexArray.setVertexAttribPointer(
                0,
                textureShaderProgram.getPositionAttributeLocation(),
                POSITION_COMPONENT_COUNT,
                0);
    }

    public void draw() {
        for (DrawCommand drawCommand : drawList) {
            drawCommand.draw();
        }
    }
}
